﻿@model AncientLand.Service.Entity.Photos
@{
    ViewBag.Title = "作品上传";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/Uploadify/swfobject.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/Uploadify/jquery.uploadify.v2.1.0.min.js")"></script>
<link href="@Url.Content("~/Scripts/Uploadify/uploadify.css")" rel="stylesheet" type="text/css" />
<style type="text/css">
    li.selected
    {
        background-color: #333333;
    }
    .text-input
    {
        -moz-font-feature-settings: inherit;
        -moz-font-language-override: inherit;
        border-color: #EAEAEA #F4F4F4 #F4F4F4 #EAEAEA;
        border-radius: 5px 5px 5px 5px;
        border-style: solid;
        border-width: 1px;
        color: #7D7D7D;
        display: block;
        font-family: inherit;
        font-size: 13px;
        font-size-adjust: inherit;
        font-stretch: inherit;
        font-style: inherit;
        font-variant: inherit;
        font-weight: inherit;
        line-height: inherit;
        margin: 0 0 10px;
        padding: 5px;
    }
</style>
<div class="page-contents clearfix">
    <div class="page-contents-wrap float-left two-column" style="width: 600px">
        <div>
            <div id="post-146" class="post-146 page type-page status-publish hentry">
                <h1 class="entry-title">
                    Upload photos</h1>
                <div class="clear">
                </div>
                <div id="commentform" style="width: 100%">
                    <div id="respond">
                        <p class="comment-form-email">
                            <label for="photos">
                                选择要上传的图片：</label>
                        </p>
                        <div class="comment-form-email">
                            <p>
                                <input id="fileInput1" name="fileInput1" type="file" /></p>
                            @*<p style="margin-top: 5px; font-size: 14px; font-weight: bold;">
                                <a href="javascript:if(checkImport()){$('#fileInput1').uploadifyUpload();}">上传图片</a></p>*@
                            <p style="margin-top: 5px; font-size: 14px; font-weight: bold;">
                                <span id="result"></span>
                            </p>
                        </div>
                        @Html.HiddenFor(model => model.ImgPath)
                        @Html.HiddenFor(model => model.ThumbnailPath)
                        <p class="form-submit">
                            <input type="submit" value="【上 传】" id="submit" name="submit" />
                        </p>
                    </div>
                    <!-- #respond -->
                </div>
            </div>
        </div>
        <!-- #post-## -->
    </div>
    <div class="sidebar-wrap float-right" style="width: 290px">
        <div class="sidebar-top">
        </div>
        <div class="sidebar" id="portrait">
            <div class="regular-sidebar clearfix">
                <div class="sidebar-widget">
                    @{Html.RenderAction("_category", "ShowCase", new { photoType = "写真" });}
                    <div style="padding: 5px 0px">
                        <input type="text" class="text-input" style="float: left" id="txtPortrait" /><a href="Javascript:void(0)"
                            style="float: right; padding-top: 6px" id="btnAddPortrait">添加分类</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="sidebar" id="wedding">
            <div class="regular-sidebar clearfix">
                <div class="sidebar-widget">
                    @{Html.RenderAction("_category", "ShowCase", new { photoType = "婚纱" });}
                    <div style="padding: 5px 0px">
                        <input type="text" class="text-input" style="float: left" id="txtWedding" /><a href="Javascript:void(0)"
                            style="float: right; padding-top: 6px" id="btnAddWedding">添加分类</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="sidebar-bottom">
        </div>
    </div>
</div>
<script type="text/javascript">
    var uploadFolder = "/UpFiles/写真/";
    var category = "";
    $(function () {

        $(".sidebar ul li a").click(function () {
            $(".sidebar ul li").each(function () { $(this).removeClass("selected") });
            $(this).parent(0).attr("class", "selected");
            return false;
        })
        $("#btnAddPortrait").click(function () {
            var folder = $("#txtPortrait").val();
            CreateFolder("/UpFiles/写真/" + folder + "/");
        })

        $("#btnAddWedding").click(function () {
            var folder = $("#txtWedding").val();
            CreateFolder("/UpFiles/婚纱/" + folder + "/");
        })

        function CreateFolder(folderPath) {
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/ShowCase/CreateFolder")',
                data: { folder: folderPath },
                success: function (data) {
                    if (data == "1") {
                        window.location.reload();
                    }
                    else
                        alert(data);
                }
            });

        }

        $('#submit').click(function () {
            if (checkImport()) {
                if ($("#wedding ul li[class='selected']").length > 0) {
                    uploadFolder = "/UpFiles/婚纱/";
                }
                if ($("#portrait ul li[class='selected']").length > 0) {
                    uploadFolder = "/UpFiles/写真/";
                }
                var temp = uploadFolder;
                category = $(".sidebar ul li[class='selected'] a").html();
                uploadFolder = escape(uploadFolder + category + "/");

                //                $('#fileInput1').uploadifySettings('scriptData', {
                //                    'photoType': encodeURI(photoType),
                //                    'category': encodeURI(category)
                //                })

                $('#fileInput1').uploadifySettings('folder', uploadFolder);
                $('#fileInput1').uploadifyUpload();
                uploadFolder = temp;

            }
        })
        //上传
        $('#fileInput1').uploadify({
            'uploader': '@Url.Content("~/Scripts/Uploadify/uploadify.swf")',
            'script': '@Url.Content("~/ShowCase/Upload")',
            // 'folder': uploadFolder,
            // 'method': 'GET',
            'cancelImg': '@Url.Content("~/Scripts/Uploadify/cancel.png")',
            'fileExt': '*.jpg;*.gif',
            'fileDesc': 'Image Files (.JPG, .GIF)',
            'sizeLimit': 1024 * 1024 * 2, //2M
            'multi': true,
            'onAllComplete': fun
        });

    });
    function fun(event, data) {
        showInfo("成功上传:" + data.filesUploaded + "<br/>出错数量：" + data.errors + "<br/>总字节数：" + (data.allBytesLoaded / 1000).toFixed(1) + "K<br/>上传速度：" + (data.speed / 1000).toFixed(1) + "KB/s", true); //showInfo方法设置上传结果     
    }
    //显示提示信息，textstyle2为绿色，即正确信息；textstyl1为红色，即错误信息
    function showInfo(msg, type) {
        var msgClass = type == true ? "textstyle2" : "textstyle1";
        $("#result").removeClass();
        $("#result").addClass(msgClass);
        $("#result").html(msg);
    }
    //如果点击‘导入文件’时选择文件为空，则提示
    function checkImport() {
        if ($(".sidebar ul li[class='selected']").length <= 0) {
            alert('请先选择要上传到那个分类！');
            return false;
        }
        if ($.trim($('#fileInput1Queue').html()) == "") {
            alert('请先选择要上传的文件！');
            return false;
        }
        return true;
    } 

</script>
